<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:if test="${buyer==null }">
	<h1 class="text-center G-MarginTop150">
		<span class="icon-frown-o"></span> 无法加载此页面
	</h1>
</c:if>
<c:if test="${buyer!=null }">
	<div class="line-big" id="write_goods_info_div">
		<input type="hidden" id="buyerId" value="${buyer.buyerId }" />
		<div class="xl1"></div>
		<div class="xl10">
			<div class="panel border-back">
				<div class="panel-body text-center">
					<h1>
						<strong>修改买家信息</strong>
					</h1>
				</div>
				<div class="panel-foot bg-white border-back">
					<div class="line-big G-MarginTopBottom20">

						<div class="xl3">
							<div class="form-group">
								<div class="label">
									<label for="buyerType">*买家类型</label>
								</div>
								<div class="field">
									<select class="input" id="buyerType">
										<option value="普通买家">普通买家</option>
										<option value="西普茗茶销售经理">西普茗茶销售经理</option>
										<option value="西普茗茶销售人员">西普茗茶销售人员</option>
										<option value="润宝集团">润宝集团</option>
										<option value="珠海兆港贸易">珠海兆港贸易</option>
										<option value="骏德酒业">骏德酒业</option>
										<option value="一级分销商">一级分销商</option>
										<option value="一级分销商销售人员">一级分销商销售人员</option>
										<option value="二级分销商">二级分销商</option>
										<option value="二级分销商销售人员">二级分销商销售人员</option>
										<option value="店铺">店铺</option>
										<option value="店铺人员">店铺人员</option>
									</select>
								</div>
							</div>
						</div>
						<div class="xl3">
							<div class="form-group">
								<c:choose>
									<c:when test="${buyer.buyerIntroducer!=null&&buyer.buyerIntroducer!='' }">
										<div class="label">
											<label for="buyerIntroducer">推荐人编号(此买家已有推荐人)</label>
										</div>
										<div class="field">
											<input type="text" class="input" value="${buyer.buyerIntroducer }" id="buyerIntroducer" data-regex="(^\S.{0,23}\S$)|(^\S{0}$)" />
										</div>
									</c:when>
									<c:otherwise>
										<div class="label">
											<label for="buyerIntroducer">推荐人编号(25位)</label>
										</div>
										<div class="field">
											<input type="text" class="input" id="buyerIntroducer" data-regex="(^\S.{0,23}\S$)|(^\S{0}$)" />
										</div>
									</c:otherwise>
								</c:choose>
							</div>
						</div>
					</div>



				</div>
				<div class="panel-foot bg-white">
					<div class="line-big G-MarginTopBottom20">
						<div class="xl4"></div>
						<div class="xl4 text-center">
							<button class="button border-blue" id="submit_buyer_button">提交信息</button>
						</div>
						<div class="xl4"></div>
					</div>
				</div>
			</div>

		</div>
		<div class="xl1"></div>
	</div>
</c:if>
<div id="add_success_div" class="G-MarginTop100" style="display: none;">
	<div class="line-big">
		<div class="xl3"></div>
		<div class="xl6 text-center">
			<h1 class="text-center">
				<span class="icon-check-circle text-yellow"></span> 修改买家信息成功了。
			</h1>
			<br />
			<p>
				<button class="button border-main click_go_to_nav_button" data-trigger-id="#sub_see_used_buyer">查看使用中的买家</button>
			</p>
		</div>
		<div class="xl3"></div>
	</div>
</div>

<div class="clearfix G-MarginTop100"></div>

<div style="display: none" id="buyerType_temp_div">${buyer.buyerType }</div>

<div style="display: none" id="time_temp_div"></div>
<script type="text/javascript">
	$(function()
	{

		$("#buyerType").val($("#buyerType_temp_div").text());

		var myDate = new Date();
		$("#time_temp_div").html(myDate.getHours() + "-" + myDate.getMinutes() + "-" + myDate.getSeconds() + "-" + myDate.getMilliseconds());

		$("#submit_buyer_button").click(function()
		{
			var buyerId = $("#buyerId").val();
			var buyerType = $("#buyerType").val();
			var buyerIntroducer = $("#buyerIntroducer").val();

			if (buyerId.length <= 0 || buyerType.length <= 0)
			{
				alert("标有*的输入项都是必填项.")
				return false;
			}

			var tips = "";
			var tips_number = 1;
			$("input[data-regex]").each(function(i, dom)
			{
				var n = $(dom);
				if (new RegExp(n.attr("data-regex")).test(n.val()) == false)
				{
					tips += tips_number++ + " . \"" + n.val() + "\" 不满足输入要求;\n";
				}
			});
			if (tips.length > 0)
			{
				alert(tips + "\n请检查一下重新输入.");
				return false;
			}

			var submit_buyer_button_html = $("#submit_buyer_button").html();
			$.ajax(
			{
				url : "admin/m_update_buyer_do",
				type : "POST",
				dataType : "json",
				beforeSend : function(XMLHttpRequest)
				{
					$("#submit_buyer_button").attr("disabled", "disabled");
					$("#submit_buyer_button").html("正在提交买家信息中...");
				},
				data :
				{
					'buyer.buyerId' : buyerId,
					'buyer.buyerType' : buyerType,
					'buyer.buyerIntroducer' : buyerIntroducer
				},
				success : function(json, textStatus)
				{
					if (json.success == true)
					{
						$("#write_goods_info_div").slideUp();
						$("#add_success_div").slideDown(function()
						{
							$(".admin").animate(
							{
								scrollTop : 0
							}, 0);
						});

					}
					else
					{
						alert(json.info);
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown)
				{
					alert("提交失败，请仔细检查您的输入是否满足要求。");
				},
				complete : function(XMLHttpRequest, textStatus)
				{
					$("#submit_buyer_button").removeAttr("disabled");
					$("#submit_buyer_button").html(submit_buyer_button_html);
				}
			});
		});

	});
</script>